﻿using SH.Common.CommonClass;
using SH.Common.CommonReturn;
using SH.Common.DataDictionary;
using SH.Multitenant.Application.IServices.IOperationLog;

using SH.Multitenant.Infrastructure.IRepository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Schema;

namespace SH.Multitenant.Application.Services
{
    public class OperationLogServices : BaseServices<OperationLog>, IOperationLogServices
    {
        private readonly IOperationLogRepository _operationLogRepository;

        public OperationLogServices(IOperationLogRepository repository) : base(repository)
        {
            _operationLogRepository = repository;
        }

        //获取操作模块
        public List<Dic> GetOperationModules()
        {
            var list = _operationLogRepository.GetDics().Where(x => x.Identification == "module").ToList();
            return list;
        }
        //多条件分页获取操作日志列表
        public async Task<ApiPaging<List<OperationLog>>> GetOperationLogs(DateTime? sDate, DateTime? eDate, string? module, string? operationName, int pageSize, int pageIndex)
        {
            Expression<Func<OperationLog, bool>> predicate = x => (sDate == null || x.OperationTime >= sDate.Value) && (eDate == null || x.OperationTime < eDate.Value.AddDays(1)) && (string.IsNullOrEmpty(module) || x.OperationModule == module) && (string.IsNullOrEmpty(operationName) || x.OperationName!.Contains(operationName));
            var list = await _operationLogRepository.PageQueryAsync(_operationLogRepository.All, predicate, "operationtime desc", pageSize, pageIndex);
            return list;
        }
    }
}
